class Solution(object):
    def levelOrder(self, root):
        """
        :type root: TreeNode
        :rtype: List[List[int]]
        """
        count = 0
        if not root:
            return []
        else:
            val_list = []
            root_list = [[root], [root]]
        while len(root_list[count % 2]) > 0:
            now_node_list = root_list[count % 2]
            count += 1
            next_node_list = []
            now_val_list = []
            for node in now_node_list:
                now_val_list.append(node.val)
                if node.left:
                    next_node_list.append(node.left)
                if node.right:
                    next_node_list.append(node.right)
            val_list.append(now_val_list)
            root_list[count % 2] = next_node_list
        return val_list
